<script setup>
// 引入数据接口
import { getGoodsHot } from '@/apis/details'
import { onMounted, ref } from 'vue';
// 接收组件传过来的id
import { useRoute } from 'vue-router'
const router = useRoute()

// 接收父组件传过来数值
const props = defineProps(['hotType'])
// 定义标题数据
const HOTTYPE = {
    1: '24小时热榜',
    2: '周热榜'
}

// 获取数据
const hotDataList = ref([])
const getHotData = async () => {
    // 调用接口
    const res = await getGoodsHot({
        id: router.params.id,
        type: props.hotType
    })
    hotDataList.value = res.data.result
}

onMounted(() => getHotData())
</script>


<template>
    <div class="goods-hot">
        <h3>{{ HOTTYPE[props.hotType] }}</h3>
        <!-- 商品区块 -->
        <RouterLink to="/" class="goods-item" v-for="item in hotDataList" :key="item.id">
            <img :src="item.picture" alt="" />
            <p class="name ellipsis">{{ item.name }}</p>
            <p class="desc ellipsis">{{ item.desc }}</p>
            <p class="price">&yen;{{ item.price }}</p>
        </RouterLink>
    </div>
</template>


<style scoped lang="scss">
.goods-hot {
    h3 {
        height: 70px;
        background: $helpColor;
        color: #fff;
        font-size: 18px;
        line-height: 70px;
        padding-left: 25px;
        margin-bottom: 10px;
        font-weight: normal;
    }

    .goods-item {
        display: block;
        padding: 20px 30px;
        text-align: center;
        background: #fff;

        img {
            width: 160px;
            height: 160px;
        }

        p {
            padding-top: 10px;
        }

        .name {
            font-size: 16px;
        }

        .desc {
            color: #999;
            height: 29px;
        }

        .price {
            color: $priceColor;
            font-size: 20px;
        }
    }
}
</style>